const gridManagerName = "test",
    TYPE_MAP = {1: "HTML/CSS", 2: "nodeJS", 3: "javaScript", 4: "前端鸡汤", 5: "PM Coffee", 6: "前端框架", 7: "前端相关"},
    GM_PUBLISH_METHOD_MAP = {
        init: {key: "init", relyInit: !1, title: "初始化", code: 'demo1.initGM(document.querySelector("table"));'},
        get: {key: "get", relyInit: !0, title: "获取表格的实时配置信息", code: `GridManager.get('${gridManagerName}');`},
        version: {key: "version", relyInit: !1, title: "获取当前GridManager的版本号", code: "GridManager.version;"},
        getLocalStorage: {
            key: "getLocalStorage",
            relyInit: !0,
            title: "获取表格用户记忆",
            code: `GridManager.getLocalStorage('${gridManagerName}');`
        },
        resetLayout: {
            key: "resetLayout",
            relyInit: !0,
            title: "重置表格布局",
            code: `GridManager.resetLayout('${gridManagerName}', '800px', '500px');`
        },
        clear: {key: "clear", relyInit: !0, title: "清除表格记忆数据", code: `GridManager.clear('${gridManagerName}');`},
        getTableData: {
            key: "getTableData",
            relyInit: !0,
            title: "获取指定tr所使用的数据",
            code: `GridManager.getTableData('${gridManagerName}');`
        },
        getRowData: {
            key: "getRowData",
            relyInit: !0,
            title: "获取指定tr所使用的数据",
            code: `GridManager.getRowData('${gridManagerName}', document.querySelector("table[grid-manager=${gridManagerName}] tbody tr"));`
        },
        updateRowData: {
            key: "updateRowData",
            relyInit: !0,
            title: "更新指定行所使用的数据",
            code: `GridManager.updateRowData('${gridManagerName}', 'id', {id: 112, title: 'ccc'});`
        },
        updateTreeState: {
            key: "updateTreeState",
            relyInit: !0,
            title: "更新树的展开状态",
            code: `GridManager.updateTreeState('${gridManagerName}', true);`
        },
        setSort: {
            key: "setSort",
            relyInit: !0,
            title: "手动设置排序",
            code: `GridManager.setSort('${gridManagerName}', {createDate: 'ASC'});`
        },
        setConfigVisible: {
            key: "setConfigVisible",
            relyInit: !0,
            title: "设置表头配置区域可视状态",
            code: `GridManager.setConfigVisible('${gridManagerName}', true);`
        },
        setLineHeight: {
            key: "setLineHeight",
            relyInit: !0,
            title: "配置行的高度",
            code: `GridManager.setLineHeight('${gridManagerName}', '70px');`
        },
        showTh: {
            key: "showTh",
            relyInit: !0,
            title: "设置列为可视状态",
            code: `GridManager.showTh('${gridManagerName}', 'pic');`
        },
        hideTh: {
            key: "hideTh",
            relyInit: !0,
            title: "设置列为隐藏状态",
            code: `GridManager.hideTh('${gridManagerName}', 'pic');`
        },
        exportGrid: {
            key: "exportGrid",
            relyInit: !0,
            title: "导出指定表格",
            code: `GridManager.exportGrid('${gridManagerName}', 'demo中使用的导出').then(res=>{console.log('success')}).catch(err=>{console.error('error', err)});`
        },
        setQuery: {
            key: "setQuery",
            relyInit: !0,
            title: "更改在生成组件时所配置的参数query",
            code: `GridManager.setQuery('${gridManagerName}', {'userName':'baukh','sex':'男'});`
        },
        setAjaxData: {
            key: "setAjaxData",
            relyInit: !0,
            title: "用于再次配置ajaxData数据",
            code: `GridManager.setAjaxData('${gridManagerName}', {data: [{title: '通过setAjaxData动态添加的数据，其它项为空'}], totals: 1});`
        },
        refreshGrid: {
            key: "refreshGrid",
            relyInit: !0,
            title: "刷新表格",
            code: `GridManager.refreshGrid('${gridManagerName}');`
        },
        renderGrid: {
            key: "renderGrid",
            relyInit: !0,
            title: "渲染表格",
            code: `GridManager.renderGrid('${gridManagerName}');`
        },
        getCheckedTr: {
            key: "getCheckedTr",
            relyInit: !0,
            title: "获取当前选中的行",
            code: `GridManager.getCheckedTr('${gridManagerName}');`
        },
        getCheckedData: {
            key: "getCheckedData",
            relyInit: !0,
            title: "获取选中行的渲染数据",
            code: `GridManager.getCheckedData('${gridManagerName}');`
        },
        setCheckedData: {
            key: "setCheckedData",
            relyInit: !0,
            title: "设置选中的数据",
            code: `GridManager.setCheckedData('${gridManagerName}', [GridManager.getTableData('${gridManagerName}')[1]]);`
        },
        cleanData: {
            key: "cleanData",
            relyInit: !0,
            title: "清除指定表格数据",
            code: `GridManager.cleanData('${gridManagerName}');`
        },
        print: {key: "print", relyInit: !0, title: "打印当前页", code: `GridManager.print('${gridManagerName}');`},
        showRow: {key: "showRow", relyInit: !0, title: "显示隐藏行", code: `GridManager.showRow('${gridManagerName}', 1);`},
        hideRow: {key: "hideRow", relyInit: !0, title: "隐藏行", code: `GridManager.hideRow('${gridManagerName}', 1);`},
        showLoading: {
            key: "showLoading",
            relyInit: !0,
            title: "显示加载中",
            code: `GridManager.showLoading('${gridManagerName}');`
        },
        hideLoading: {
            key: "hideLoading",
            relyInit: !0,
            title: "隐藏加载中",
            code: `GridManager.hideLoading('${gridManagerName}', 300);`
        },
        destroy: {
            key: "destroy",
            relyInit: !0,
            title: "消毁指定的GridManager实例",
            code: `GridManager.destroy('${gridManagerName}');`
        }
    }, arg = {
        gridManagerName: "test",
        width: "100%",
        height: "100%",
        autoOrderConfig: {fixed: "left"},
        checkboxConfig: {key: "id", fixed: "left"},
        supportAjaxPage: !0,
        sortMode: "single",
        supportMenu: !0,
        menuHandler: e => (e.unshift({
            content: "自定义菜单", line: !0, onClick: e => {
                alert(e)
            }
        }), e),
        useCellFocus: !0,
        useHideRow: !0,
        supportMoveRow: !0,
        moveRowConfig: {
            key: "priority", useSingleMode: !0, fixed: "left", handler: (e, t) => {
                console.log(e, t)
            }
        },
        disableCache: !1,
        ajaxData: function (e, t) {
            var local_host = window.location.host;          // 获取当前IP
            // return document.querySelector('[name="type"]').value = t.type || -1, "https://www.lovejavascript.com/blogManager/getBlogList"
            return "/personal-center/getBlogList"

        },
        exportConfig: {
            fileName: e => {
                const t = new Date;
                let a = `${t.getFullYear()}-${t.getMonth() + 1}-${t.getDate()}`;
                for (let t in e) a = `${a}-${t}=${e[t]}`;
                return a
            }, suffix: "xls"
        },
        ajaxType: "POST",
        checkedBefore: function (e, t, a) {
            return console.log("checkedBefore==", e, t, a), a && 90 === a.id && alert("该节点在checkedBefore中配置为不可选"), a && 90 !== a.id
        },
        checkedAfter: function (e, t, a) {
            console.log("checkedAfter==", e, t, a)
        },
        checkedAllBefore: function (e, t) {
            console.log("checkedAllBefore==", e, t)
        },
        checkedAllAfter: function (e, t) {
            console.log("checkedAllAfter==", e, t)
        },
        sortingBefore: function (e) {
            console.log("sortingBefore", e)
        },
        sortingAfter: function (e) {
            console.log("sortingAfter", e)
        },
        ajaxBeforeSend: function (e) {
            console.log("ajaxBeforeSend")
        },
        ajaxSuccess: function (e) {
            console.log("ajaxSuccess")
        },
        ajaxError: function (e) {
            console.log("ajaxError")
        },
        ajaxComplete: function (e) {
            console.log("ajaxComplete")
        },
        adjustBefore: e => {
            console.log("adjustBefore=>", e)
        },
        adjustAfter: e => {
            console.log("adjustAfter=>", e)
        },
        responseHandler: e => (e.data.forEach((e => {
            e.priority = e.id
        })), e),
        rowRenderHandler: (e, t) => e,
        emptyTemplate: e => `<div style="text-align: center;">${e.query.title ? "搜索为空" : "暂无数据"}</div>`,
        columnData: [{
            key: "title",
            text: "标题",
            disableMoveRow: !0
        }, {
            key: "document_number",
            text: "公文编号",
            align: "center",
            // sorting: "",
            disableMoveRow: !0,
        }, {
            key: "real_name",
            text: "拟稿人",
            align: "center",
            disableMoveRow: !0
        }, {
            key: "department",
            text: "拟稿科室",
            align: "center",
        }, {
            key: "create_time",
            text: "收文时间",
            align: "center",
        }, {
            key: "action",
            width: "100px",
            align: "center",
            fixed: "right",
            disableMoveRow: !0,
            disableRowCheck: !0,
            text: '<span style="color: red">操作</span>',
            template: (e, t) => `<a class="plugin-action" href="${t.url}">查看</a>`
            }]
    }, demo1 = {
        initSearch: function () {
            document.querySelector(".search-action").addEventListener("click", (function () {
                change_color("");
                var e = {
                    title: document.querySelector('[name="title"]').value,
                    document_number: document.querySelector('[name="document_number"]').value,
                    real_name: document.querySelector('[name="real_name"]').value,
                    department: document.querySelector('[name="department"]').value
                };
                table.GM("setQuery", e, (function () {
                    console.log("setQuery执行成功")
                }))
            }))
        }, initFN: () => {

        }, initGM: function () {
            new window.GridManager(table, arg, (e => {
                console.log("渲染完成后的回调函数:", e), console.log(arg.columnData)
            }))
        }, editRowData: function (e) {
            window.GridManager.updateRowData("test", "id", {
                id: window.parseInt(e.getAttribute("data-id")),
                lastDate: (new Date).getTime()
            })
        }
    }, table = document.querySelector("table");
demo1.initSearch(table), demo1.initGM(table), demo1.initFN();

var onlick_list = document.getElementsByClassName("onclick-search");

for (var i=0; i<onlick_list.length; i++){
    onlick_list[i].onclick=function() {
        // this.className="onclick-search add-backbround-color";
        change_color(this.getAttribute("data-value"));
        var e = {
            datavalue: this.getAttribute("data-value")
        };
        table.GM("setQuery", e, (function () {
            console.log("setQuery执行成功")
        }))
    }
}

function change_color(datavalue) {
    for (var j=0; j<onlick_list.length; j++){
        if (onlick_list[j].getAttribute("data-value") === datavalue) {
            onlick_list[j].className = "onclick-search add-backbround-color";
        }else {
            onlick_list[j].className = "onclick-search";
        }
    }
}